import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:overlay_support/overlay_support.dart';
import 'package:qgchat/common/global/global.dart';

import '../../../http/apis/common.dart';

class Convention extends StatefulWidget {
  Convention({Key key}) : super(key: key);

  @override
  _ConventionState createState() => _ConventionState();
}

class _ConventionState extends State<Convention> {
  @override
  void initState() { 
    super.initState();
    initRequest();
  }
  // List anchors = List.generate(33, (val)=> {"id":1045,"member_tel":null,"member_name":"o8cKqw-zfuidaiLIW0JSpM4M5nBA","member_nickname":"じ柒柒ᝰ" + val.toString(),"member_createtime":"1589047465","member_type":1,"password":null,"member_token":"4d28296b937d81c2d1c5841d2f108e8f","balance":"0.00","gold":2126,"member_head":"http:\/\/thirdwx.qlogo.cn\/mmopen\/vi_32\/DibAj5nQus6pFb4wCuz1hoqFaINibdcMeUY0wgj2FudHbwBtKJzHML8jtwhEDpO4OCicibstQxOyf3STJTvldTFnkQ\/132","member_follow":0,"member_exp":2126,"last_login":"1590457739","disturb":0,"cash_balance":"790.20","invitationcode":"7b1d9f","prohibit":"1590813675","is_rb":0,"onlyset":"4c083f9f43ad1c59","lastonlyset":"","reasion":""});
  // List users = [{"id":9,"member_tel":null,"member_name":"3AFDE9A55FE6BB6A59CB45957FB029D0","member_nickname":"独绽客服","member_createtime":"1577435667","member_type":0,"password":null,"member_token":"6fe209f6d8e59f5e69fd5b69def412b8","balance":"0.00","gold":56284,"member_head":"http:\/\/thirdqq.qlogo.cn\/g?b=oidb&k=faA0vNxEmibq4EMQLu1yNXA&s=640&t=1567448836","member_follow":0,"member_exp":43716,"last_login":"1578629545","disturb":0,"cash_balance":"0.00","invitationcode":"866beb","prohibit":"1577628664","is_rb":0,"onlyset":"a7cd45b2e660801d","lastonlyset":"","reasion":""},{"id":9,"member_tel":null,"member_name":"3AFDE9A55FE6BB6A59CB45957FB029D0","member_nickname":"独绽客服","member_createtime":"1577435667","member_type":0,"password":null,"member_token":"6fe209f6d8e59f5e69fd5b69def412b8","balance":"0.00","gold":56284,"member_head":"http:\/\/thirdqq.qlogo.cn\/g?b=oidb&k=faA0vNxEmibq4EMQLu1yNXA&s=640&t=1567448836","member_follow":0,"member_exp":43716,"last_login":"1578629545","disturb":0,"cash_balance":"0.00","invitationcode":"866beb","prohibit":"1577628664","is_rb":0,"onlyset":"a7cd45b2e660801d","lastonlyset":"","reasion":""},{"id":9,"member_tel":null,"member_name":"3AFDE9A55FE6BB6A59CB45957FB029D0","member_nickname":"独绽客服","member_createtime":"1577435667","member_type":0,"password":null,"member_token":"6fe209f6d8e59f5e69fd5b69def412b8","balance":"0.00","gold":56284,"member_head":"http:\/\/thirdqq.qlogo.cn\/g?b=oidb&k=faA0vNxEmibq4EMQLu1yNXA&s=640&t=1567448836","member_follow":0,"member_exp":43716,"last_login":"1578629545","disturb":0,"cash_balance":"0.00","invitationcode":"866beb","prohibit":"1577628664","is_rb":0,"onlyset":"a7cd45b2e660801d","lastonlyset":"","reasion":""},{"id":9,"member_tel":null,"member_name":"3AFDE9A55FE6BB6A59CB45957FB029D0","member_nickname":"独绽客服","member_createtime":"1577435667","member_type":0,"password":null,"member_token":"6fe209f6d8e59f5e69fd5b69def412b8","balance":"0.00","gold":56284,"member_head":"http:\/\/thirdqq.qlogo.cn\/g?b=oidb&k=faA0vNxEmibq4EMQLu1yNXA&s=640&t=1567448836","member_follow":0,"member_exp":43716,"last_login":"1578629545","disturb":0,"cash_balance":"0.00","invitationcode":"866beb","prohibit":"1577628664","is_rb":0,"onlyset":"a7cd45b2e660801d","lastonlyset":"","reasion":""},{"id":9,"member_tel":null,"member_name":"3AFDE9A55FE6BB6A59CB45957FB029D0","member_nickname":"独绽客服","member_createtime":"1577435667","member_type":0,"password":null,"member_token":"6fe209f6d8e59f5e69fd5b69def412b8","balance":"0.00","gold":56284,"member_head":"http:\/\/thirdqq.qlogo.cn\/g?b=oidb&k=faA0vNxEmibq4EMQLu1yNXA&s=640&t=1567448836","member_follow":0,"member_exp":43716,"last_login":"1578629545","disturb":0,"cash_balance":"0.00","invitationcode":"866beb","prohibit":"1577628664","is_rb":0,"onlyset":"a7cd45b2e660801d","lastonlyset":"","reasion":""}];
  List anchors;
  List users;
  initRequest() async {
    // Dio dio = Dio();
    // var res = await dio.get("http://192.168.1.33:8886/api/anchor/ban");
    var res = await CommonApis.getCommonInfo("ban");
    if (res["status"] == 1) {
      anchors = res["data"]["anchors"];
      users = res["data"]["users"];
      setState(() {});
    } else {
      toast(res["msg"]);
    }
  }
  String userNamePrivacy(String name) {
    if (name.length == 1) {
      return name;
    } else if(name.length == 2) {
      return name.split("")[0] + "*";
    }else {
      String res = name.split("")[0];
      for (int i = 0; i < name.length - 2; i++) {
        res += "*";
      }
      return res + name.split("")[name.length-1];
    }
  }
  Widget getBanList(String type) {
    List temp;
    switch (type) {
      case "anchors":
        temp = anchors;
        break;
      case "users":
        temp = users;
        break;
      default:
    }
    return Container(
      child: GridView.count(
        crossAxisCount: 3,
        scrollDirection: Axis.vertical,
        mainAxisSpacing: 10,
        // physics: NeverScrollableScrollPhysics(),
        childAspectRatio: 6,
        children: temp.map((item)=>Container(child: Text(userNamePrivacy(item["member_nickname"]),textAlign: TextAlign.center,))).toList(),
      ),
        margin: EdgeInsets.only(
          top: px(58),
        ),
        padding: EdgeInsets.symmetric(horizontal: px(20),vertical: px(30)),
        width: px(1019),
        height: px(329),
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(
            px(30),
          ),
        ),
      );
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        padding: EdgeInsets.only(top: px(20), left: px(30), right: px(30)),
        decoration: BoxDecoration(
          // color: Colors.red,
          image: DecorationImage(
            image: AssetImage(
              'assets/images/bulletin.png',
            ),
            fit: BoxFit.cover,
          ),
        ),
        child: ListView(
          children: <Widget>[
            Container(
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: <Widget>[
                  GestureDetector(
                    onTapUp: (v)=>Navigator.pop(context),
                    child: Container(
                      child: Icon(
                        Icons.navigate_before,
                        color: Colors.white,
                        size: px(36),
                      ),
                    ),
                  ),
                  Text(
                    '绿色公告',
                    style: TextStyle(
                      fontSize: px(40),
                      color: Colors.white,
                    ),
                  ),
                  // 占位
                  Container()
                ],
              ),
            ),
            // 封禁主播
            Container(
              margin: EdgeInsets.only(
                top: px(89),
              ),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Container(
                    child: Text(
                      '封禁主播名单:',
                      style: TextStyle(
                        fontSize: px(32),
                        color: Colors.white,
                      ),
                    ),
                  ),
                  anchors != null ? getBanList("anchors") : SizedBox(height: 0,),
                ],
              ),
            ),
            // 封禁用户
            Container(
              margin: EdgeInsets.only(
                top: px(61),
              ),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Container(
                    child: Text(
                      '封禁用户名单:',
                      style: TextStyle(
                        fontSize: px(32),
                        color: Colors.white,
                      ),
                    ),
                  ),
                  users != null ? getBanList("users") : SizedBox(height: 0,),
                ],
              ),
            ),
            // 文明公约
            Container(
              padding: EdgeInsets.only(
                bottom: px(123),
              ),
              margin: EdgeInsets.only(
                top: px(102),
              ),
              child: Image.asset(
                'assets/images/bullein_bto.png',
              ),
            ),
          ],
        ),
      ),
    );
  }
}
